#pragma config(Sensor, S1,     lightSensor,         sensorLightActive)

task main()
{
   wait1Msec(100);
   nMaxRegulatedSpeedNxt = 500;
   int negro = SensorValue[lightSensor];
   nxtDisplayCenteredTextLine(4, "%d", negro);
   wait1Msec(1000);
   motor[motorB] = 60;
   motor[motorC] = -60;
   wait1Msec(300);

   motor[motorB] = 0;
   motor[motorC] = 0;
   int blanco = SensorValue[lightSensor];
   nxtDisplayCenteredTextLine(4, "%d", blanco);
   wait1Msec(1000);
   int media = (negro + blanco)/2;

   motor[motorB] = -60;
   motor[motorC] = 60;
   wait1Msec(200);

   nxtDisplayCenteredTextLine(4, "%d", media);
   motor[motorB] = 0;
   motor[motorC] = 0;
   wait1Msec(1000);
   nMaxRegulatedSpeedNxt = 1000;
   while(true)
   {
      if(SensorValue[lightSensor] < media){
        motor[motorB] = 60;
  	motor[motorC] = 0;
      }
      else
      {
        motor[motorB] = 0;
  	motor[motorC] = 60;
      }
   }
}
